package main.java.controller;

import main.java.dao.DoctorDao;
import main.java.dao.impl.DoctorDaoImpl;
import main.java.polo.Doctor;

import java.util.List;
import java.util.Scanner;

public class DoctorController {
    /**
     * 插入医生信息
     * @return 插入成功返回1，失败返回0
     */
    public static int insert()
    {
        DoctorDao doctorDao = new DoctorDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入医生姓名，时间，科室");
        String drName= scanner.next();
        String drTime= scanner.next();
        String drRoom= scanner.next();
        Doctor doctor = new Doctor(null,drName,drTime,drRoom);
        return doctorDao.insert(doctor);
    }

    /**
     * 修改医生信息
     * @return 修改成功返回1，失败返回0
     */
    public static int update( ){
        DoctorDao doctorDao = new DoctorDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入医生id，姓名，时间，科室");
        int drId = scanner.nextInt();
        String drName= scanner.next();
        String drTime= scanner.next();
        String drDept= scanner.next();
        Doctor doctor = new Doctor(drId,drName,drTime,drDept);
        return doctorDao.update(doctor);
    }

    /**
     * 删除医生信息
     * @return 删除成功返回1，失败返回0
     */
    public static int delete( ){
        DoctorDao doctorDao = new DoctorDaoImpl();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入医生id");
        int drId = scanner.nextInt();
        return doctorDao.delete(drId);
    }

    public static void selectAll() {
        DoctorDao doctorDao = new DoctorDaoImpl();
        List<Doctor> doctorList = doctorDao.selectAll();
        for (Doctor doctor : doctorList) {
            System.out.println(doctor);
        }
    }

}
